/* Copyright (C) 1997-2005, Antony L Hosking.
 * All rights reserved.  */
package Translate;

import java.util.HashMap;

public class Temp {
    private static int count;
    private final String name;

    public String toString() {
        return name;
    }

    public Temp(String n) {
        name = n;
    }

    public Temp() {
        this("t." + count++);
    }

    public boolean spillable = true;
    
    public static interface Map {
        public Temp get(Temp t);
        
        public static class Default implements Map {
            public Temp get(Temp t) {
                return t;
            }
        }
    }

    public static class Label {
        private final String string;
        private static int count;
        private static HashMap<String, Label> map = new HashMap<String, Label>();

        /**
         * a printable representation of the label, for use in assembly language
         * output.
         */
        public String toString() {
            return string;
        }

        /**
         * Makes a new label that prints as "s".
         */
        public static Label get(String s) {
            Label l = map.get(s);
            if (l == null)
                l = new Label(s);
            return l;
        }

        private Label(String s) {
            string = s;
            map.put(s, this);
        }

        /**
         * Makes a new label with an arbitrary name.
         */
        public Label() {
            this("L." + count++);
        }
    }

}
